package com.aretias.jkholdings.repository;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;

import com.aretias.jkholdings.model.Product;
import com.aretias.jkholdings.model.ProductParam;

@Repository
public class ProductRepositoryImpl implements ProductRepository {
	
	private static final String NAMESPACE = "aretias.jkholding.product.";
	
	@Autowired
	private SqlMapClientTemplate client;
	
	@Override
	public int insertProduct(ProductParam param) {
		return (Integer) client.insert( NAMESPACE + "insertProduct", param);
	}

	@Override
	public int updateProduct(ProductParam param) {
		return client.update(NAMESPACE + "updateProduct", param);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Product> selectProductsList(ProductParam param) {
		return client.queryForList(NAMESPACE + "selectProductsList", param);
	}

	@Override
	public Product selectProduct(ProductParam param) {
		return (Product) client.queryForObject(NAMESPACE + "selectProduct", param);
	}

	@Override
	public void deleteProduct(ProductParam param) {
		client.delete(NAMESPACE + "deleteProduct", param);
	}

	@Override
	public int selectProductsListCount(ProductParam param) {
		return (Integer) client.queryForObject(NAMESPACE + "selectProductsListCount", param);
	}

}
